<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取不匹配遮罩的起始子字符串的长度</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.strcspn" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strcspn</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">strcspn</span> &mdash; <span class="dc-title">获取不匹配遮罩的起始子字符串的长度</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strcspn-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strcspn</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str1</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$str2</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>
  ]] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   返回 <code class="parameter">str1</code> 中，所有字符都<em class="emphasis">不</em>存在于 <code class="parameter">str2</code> 范围的起始子字符串的长度。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strcspn-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str1</code></dt>

     <dd>

      <p class="para">
       第一个字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">str2</code></dt>

     <dd>

      <p class="para">
       第二个字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">start</code></dt>

     <dd>

      <p class="para">
       查找的起始位置。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       查找的长度。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strcspn-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   以整型数返回子串的长度。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strcspn-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5964">
   <p><strong>Example #1 <span class="function"><strong>strcspn()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'abcd'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'abcd'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$c&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'l'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$d&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'world'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$d</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
int(0)
int(2)
int(2)
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strcspn-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strcspn-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="strspn.html" class="function" rel="rdfs-seeAlso">strspn()</a> - 计算字符串中全部字符都存在于指定字符集合中的第一段子串的长度。</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>